﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Sprites/RimLight"
 {
     Properties
     {
         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
         _IgnoreColor ("IgnoreSelectedColor", Color) = (0,0,0,1)
         _IgnoreThreshold("_IgnoreThreshold", Range(0, 1)) = 0.1
     }
 
     SubShader
     {
         Tags
         { 
             "Queue"="Transparent" 
             "IgnoreProjector"="True" 
             "RenderType"="Transparent" 
             "PreviewType"="Plane"
             "CanUseSpriteAtlas"="True"
         }
 
         Cull Off
         Lighting Off
         ZWrite Off
         Fog { Mode Off }
         Blend One OneMinusSrcAlpha
 
         Pass
         {
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile DUMMY PIXELSNAP_ON
             #include "UnityCG.cginc"

             float _IgnoreThreshold;
             fixed4 _IgnoreColor;

             struct appdata_t
             {
                 float4 vertex   : POSITION;
                 float4 color    : COLOR;
                 float4 normal    : NORMAL;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f
             {
                 float4 vertex   : SV_POSITION;
                 fixed4 color    : COLOR;
                 half2 texcoord  : TEXCOORD0;
                 float4 normal  : TEXCOORD1;
             };
 
             v2f vert(appdata_t IN)
             {
                 v2f OUT;
                 OUT.vertex = UnityObjectToClipPos(IN.vertex);
                 OUT.texcoord = IN.texcoord;
                 OUT.color = IN.color;
                 OUT.normal = IN.normal;
                 return OUT;
             }
 
             sampler2D _MainTex;
 
             fixed4 frag(v2f IN) : COLOR
             {
                // fixed4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
                // fixed3 blackThreshold = fixed3(_IgnoreThreshold, _IgnoreThreshold, _IgnoreThreshold); // 例如，允许RGB每个通道有0.01的偏差
                // fixed3 colorDiff = abs(col.rgb - _IgnoreColor.rgb);
                // bool is_equal = (colorDiff.r + colorDiff.g + colorDiff.b) / 3.0f <= _IgnoreThreshold;

                // f.position = UnityObjectToClipPos(v.vertex);
                const fixed3 viewDir = normalize(UnityWorldSpaceViewDir(IN.vertex));
                float NdotV = dot(IN.normal, viewDir);
                 return float4(NdotV, NdotV, NdotV, 1);
                 
                // if (is_equal)
                // {  
                //     // 如果颜色接近黑色，则设置为透明  
                //     col.a = 0;
                // }
             
                 // return col;
             }
         ENDCG
         }
     }
 }
